package Servlet.Manager;

import Dao.InsertBookDao;
import Table.Book;
import com.alibaba.fastjson.JSON;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/managerInsertBookServlet")
public class ManagerInsertBookServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("application/json;charset=utf-8");
        String book = req.getParameter("book");
        Book book1 = JSON.parseObject(book, Book.class);
        Boolean flag = InsertBookDao.Insert(book1);
        PrintWriter out = resp.getWriter();
        out.print(flag);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }
}
